<template>
	<view>
		<view class="list_item" v-for="(listItem, index) in orderList" :key="index">
			<view class="info_panel">
				<image class="image" :src="listItem.image" mode=""></image>
				<view class="info">
					<view class="info_header">
						<viwe class="title">
							<text class="titile_text">{{listItem.name}}</text>
							<view class="sign green" v-if="listItem.zhengce == enums['服务政策']['公益']">公益</view>
							<view class="sign orange" v-if="listItem.zhengce == enums['服务政策']['常规']">常规</view>
						</viwe>
						<view class="type" v-if="listItem.status == enums['用户订单状态']['已预约']">已预约</view>
						<view class="type" v-if="listItem.status == enums['用户订单状态']['已服务']">已服务</view>
						<view class="type" v-if="listItem.status == enums['用户订单状态']['已超时']">已超时</view>
						<view class="type" v-if="listItem.status == enums['用户订单状态']['老人已取消'] || listItem.status == enums['用户订单状态']['机构已取消']">已取消</view>
						<view class="type" v-if="listItem.status == enums['用户订单状态']['待评价']">待评价</view>
					</view>
					<view class="info_container">
						<view class="text">{{ listItem.content }}</view>
					</view>
					<veiw class="info_footer">
						<view class="organization">·{{ listItem.companyName }}</view>
					</veiw>
				</view>
			</view>
			<view class="price_panel">
				<view class="price">
					<view class="total">总价：¥{{ listItem.money | toFixed(2) }}</view>
					<view class="subsidy">补助金额：¥{{ listItem.subsidy | toFixed(2) }}</view>
					<view class="payment">实付款：¥{{ listItem.answer | toFixed(2) }}</view>
				</view>
				<view class="btn_panel">
					<view class="btn_left"><view class="cancel" v-if="listItem.status == enums['用户订单状态']['已预约']" @tap="cancelOrder(listItem.id)">取消订单</view></view>
					<view class="btn_right">
						<view class="detail" @tap="toDetail(listItem)">订单详情</view>
						<view class="confirm" v-if="listItem.status == enums['用户订单状态']['待评价']" @tap="evaluate(listItem.id)">去评价</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import * as userServeApi from '@/api/userApi/serve.js';
import { HTTP_SERVER_URL } from '@/config';
export default {
	props: {
		orderList: null
	},
	data() {
		return {
			enums: this.$enums,
			HTTP_SERVER_URL,
		};
	},
	methods: {
		// this.$emit('search');
		toDetail(data) {
			uni.navigateTo({
				url: `/pages/mine/order/orderDetail/orderDetail?id=${data.id}`
			});
		},
		evaluate(id) {
			uni.navigateTo({
				url: `/pages/mine/order/evaluate/evaluate?id=${id}`
			});
		},
		cancelOrder(id){
			if(id){
				userServeApi
					.cancelOrder({ id: id })
					.then(res => {
						if (res.code === 0) {
							this.$emit('search');
						}
					})
					.catch(e => {
						uni.showToast({
							title: e.msg,
							icon: 'none',
							duration: 1000
						});
					});
			}
		}
	}
};
</script>

<style lang="stylus">

</style>
